package cn.hrms.controller;

import cn.hrms.domain.Employee;
import cn.hrms.domain.web.R;
import cn.hrms.domain.web.TableDataInfo;
import cn.hrms.service.IEmployeeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: @date: 2024/12/18 - 13:32
 * @mail: luxiaoxiao@qq.com
 * @info:
 * @author xiaokai
 */
@Slf4j
@RestController
@RequestMapping("/admin/employee")
@RequiredArgsConstructor
public class EmployeeController extends BaseController {
	private final IEmployeeService employeeService;

	/**
	 * 查询员工管理列表
	 */
	@GetMapping("/list")
	public TableDataInfo list(Employee employee) {
		startPage();
		List<Employee> list = employeeService.selectEmployeeList(employee);
		return getDataTable(list);
	}

	/**
	 * 获取员工管理详细信息
	 */
	@GetMapping(value = "/{empNo}")
	public R<Employee> getInfo(@PathVariable("empNo") Long empNo) {
		return R.ok(employeeService.selectEmployeeByEmpNo(empNo));
	}

	/**
	 * 新增员工管理
	 */
	@PostMapping
	public R<Void> add(@RequestBody Employee employee) {
		return toAjax(employeeService.insertEmployee(employee));
	}

	/**
	 * 修改员工管理
	 */
	@PutMapping
	public R<Void> edit(@RequestBody Employee employee) {
		return toAjax(employeeService.updateEmployee(employee));
	}

	/**
	 * 删除员工管理
	 */
	@DeleteMapping("/{empNos}")
	public R<Void> remove(@PathVariable Long[] empNos) {
		return toAjax(employeeService.deleteEmployeeByEmpNos(empNos));
	}
}
